package com.correction.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.correction.classes.Examen;
import com.correction.classes.Utilisateur;
import com.correction.service.ExamenDAO;

public class GetFinichedExamByStudentList extends HttpServlet {
	private HttpSession session;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		session = request.getSession(true);
		try {
			Utilisateur professeur = (Utilisateur) session.getAttribute("user");
			List<Examen> profExamens = professeur.getExamens();

			int studentId = Integer.parseInt(request.getParameter("etudiant"));
			List<Examen> examens = ExamenDAO.getFinichedExam(studentId,profExamens);

			String data = "";
			for (Examen examen : examens) {
				int value = examen.getIdExamen();
				String name = examen.getTitre();
				data += "<option value='" + value + "'>" + name + "</option>";
			}
			out.print(data);
		} catch (Exception ex) {
			out.print("Error getting exams name..." + ex.toString());
		} finally {
			out.close();
		}
	}
}
